package com.project.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.ProductBean;
import com.project.bean.SellBean;
import com.project.bean.SellCarBean;
import com.project.bean.UserBean;
import com.project.service.ISellService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDate;
import java.util.List;

@RestController
@RequestMapping("sell")
public class SellController {
    @Autowired
    private ISellService sellService;

    @RequestMapping("addOrder")
    public String addOrder(HttpServletRequest req, SellBean sellBean) {
        UserBean user = (UserBean)req.getSession().getAttribute("loginUser");
        sellService.addOrder(user.getId(), sellBean);
        return "ok";
    }

    @RequestMapping("findByItem")
    public IPage<SellBean> findByItem(Integer pageNO, String customerName, LocalDate startDate, LocalDate endDate) {
        return sellService.findByItem(pageNO, customerName, startDate, endDate);

    }


    @RequestMapping("findById")
    public SellBean findById(Integer id) {
        return sellService.findById(id);
    }
}
